package com.ittest.utils;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

@Component
public class CodeUtils {

    private String [] patch = {"000000","00000","0000","000","00","0",""};

    public String generator(String tele){
        int hash = tele.hashCode();//获取手机（tele）号的hash值
        int encryption = 2020666; //通过这个固定数进行异或运算
        long result = hash ^ encryption;//这里进行第一步异或运算
        long nowTime = System.currentTimeMillis();//这里获取到系统时间
        result = result ^ nowTime;//在与系统时间进行异或运算
        long code = result % 1000000;//在对1000000取余
        code = code < 0 ? -code : code;
        String codeStr = code + "";
        int len = codeStr.length();
        return patch[len] + codeStr;

    }

    @Cacheable(value = "smsCode",key = "#tele")
    public String get(String tele) {
        return null;
    }

//    public static void main(String[] args) {
//        CodeUtils codeUtils = new CodeUtils();
//        String generator = codeUtils.generator("17331988610");
//        System.out.println(generator);
//    }
}
